package chapter3;

import java.util.PriorityQueue;

public class HeapSortTest {

    public void sortedArrDistanceLessK(int[] arr,int k){
        PriorityQueue<Integer> heap = new PriorityQueue<>();//默认小根堆
        int index = 0;
        for (;index < Math.min(k,arr.length);index++){
            heap.add(arr[index]);
        }
        int i =0;
        for (;index < arr.length;i++,index++){
            arr[i] = heap.poll();
            heap.add(arr[index]);
        }
        while (!heap.isEmpty()){
            arr[i++] = heap.poll();
        }
    }

    public static void main(String[] args) {

    }
}
